import Cors from 'cors';

/*
 * Initialize the cors middleware
 *
 * Reference:
 * - https://github.com/vercel/next.js/tree/canary/examples/api-routes-cors
 */
export const createCorsMiddleware =
  // You can read more about the available options here: https://github.com/expressjs/cors#configuration-options
  Cors({
    // Reflect the request origin, as defined by req.header('Origin')
    origin: true,
    // Only allow requests with GET, POST and OPTIONS
    methods: ['GET', 'POST', 'OPTIONS', 'HEAD'],
    credentials: true,
    maxAge: 21600, // 6 hours
  });
